<template>
  <div class="postbody">
    <div class="postitem3" v-if="post.images.length>=3">
      <!-- 这里是三张图片的文章 -->
      <h4 class="post-title">
        <a :href="'/post/postDetails?id='+post.id" class="title">{{post.title}}</a>
      </h4>
      <p class="content">
        <a :href="'/post/postDetails?id='+post.id">{{post.summary}}</a>
      </p>
      <div class="coverImg">
        <a :href="'/post/postDetails?id='+post.id">
          <img :src="post.images[0]" alt />
        </a>
        <a :href="'/post/postDetails?id='+post.id">
          <img :src="post.images[1]" alt />
        </a>
        <a :href="'/post/postDetails?id='+post.id">
          <img :src="post.images[2]" alt />
        </a>
      </div>
      <div class="userInfo">
        <div class="leftInfo">
          <span class="destCity">
            <i data-v-0bb1a5cc class="el-icon-location-outline"></i>
            {{post.cityName}}
          </span>
          <div class="postuser">
            by
            <a href="javascript:;">
              <img
                v-if="post.account.defaultAvatar"
                :src="$axios.defaults.baseURL+post.account.defaultAvatar"
                alt
              />
              <img v-else src="@/assets/test.jpg" alt />
            </a>
            <a href="javascript:;" class="nickname">{{post.account.nickname}}</a>
            <span>
              <i data-v-0bb1a5cc class="el-icon-view"></i>
              {{post.watch}}
            </span>
          </div>
        </div>
        <div class="rightInfo">
          <span class="dianzan">{{post.like||'0'}} 赞</span>
        </div>
      </div>
    </div>
    <div class="postitem1" v-else-if="post.images.length>=1||post.images.length==0">
      <!-- 这里是单张图片的文章 -->
      <div class="leftcover">
        <img v-if="post.images.length>0" :src="post.images[0]" alt />
        <img v-else src="@/assets/test.jpg" alt />
      </div>
      <div class="rightcontent">
        <h4 class="post-title">
          <a href="#" class="title">{{post.title}}</a>
        </h4>
        <p class="content">{{post.summary}}</p>
        <div class="userInfo">
          <div class="leftInfo">
            <span class="destCity">
              <i data-v-0bb1a5cc class="el-icon-location-outline"></i>
              {{post.cityName}}
            </span>
            <div class="postuser">
              by
              <a href="javascript:;">
                <img
                  v-if="post.account.defaultAvatar"
                  :src="$axios.defaults.baseURL+post.account.defaultAvatar"
                  alt
                />
                <img v-else src="@/assets/test.jpg" alt />
              </a>
              <a href="javascript:;" class="nickname">{{post.account.nickname}}</a>
              <span>
                <i data-v-0bb1a5cc class="el-icon-view"></i>
                {{post.watch}}
              </span>
            </div>
          </div>
          <div class="rightInfo">
            <span class="dianzan">{{post.like||'0'}} 赞</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    post: {
      type: Object,
      default: {}
    }
  }
};
</script>
<style lang="less" scoped>
.common() {
  padding: 20px 0;
  width: 100%;
  border-bottom: 1px solid #eee;
}
.commontitle() {
  margin-bottom: 15px;
  font-weight: 400;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 18px;
  .title {
    &:hover {
      color: orange;
    }
  }
}
.commonContent() {
  margin-bottom: 15px;
  line-height: 1.5;
  font-size: 14px;
  color: #666;
  height: 63px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.commonuserInfo() {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .leftInfo {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #999;
    .destCity {
      margin-right: 10px;
    }
    .postuser {
      img {
        width: 16px;
        height: 16px;
        border-radius: 8px;
        vertical-align: middle;
      }
      .nickname {
        font-size: 14px;
        margin-right: 10px;
        color: orange;
      }
    }
  }
  .rightInfo {
    color: orange;
  }
}
.postbody {
  .postitem3 {
    .common();
    .post-title {
      .commontitle();
    }
    .content {
      .commonContent();
      a {
        &:hover {
          color: #666;
        }
      }
    }
    .coverImg {
      display: flex;
      justify-content: space-between;
      margin: 15px 0;
      img {
        width: 220px;
        height: 150px;
        object-fit: cover;
        display: block;
      }
    }
    .userInfo {
      .commonuserInfo();
    }
  }
  .postitem1 {
    padding: 20px 0;
    border-bottom: 1px solid #eee;
    display: flex;
    .leftcover {
      img {
        width: 220px;
        height: 150px;
        object-fit: cover;
      }
    }
    .rightcontent {
      margin-left: 10px;
      overflow: hidden;
      flex: 1;
      .post-title {
        .commontitle();
      }
      .content {
        .commonContent();
        a {
          &:hover {
            color: #666;
          }
        }
      }
      .userInfo {
        .commonuserInfo();
      }
    }
  }
}
</style>